/**
* Created by wl
* 基金储备库-头部信息
*/
<template>
    <div>
        <div class="ca-box ca-p-20" v-if="!showEdit">
            <el-row>
                <el-col class="ca-align-right">
                    <el-button type="text"  class="ca-edit-btn el-icon-edit" @click="showEdit = true" :disabled="!isAuthEditPre" v-if="$route.name.includes('pre-investment-funds')">编辑</el-button>
                    <el-button type="text"  class="ca-edit-btn el-icon-edit" @click="showEdit = true" :disabled="!isAuthEdit" v-else>编辑</el-button>
                </el-col>
            </el-row>
            <div >
                <el-row>
                    <el-col :span="6" class="ca-border-r ca-m-r-20" style="text-align: center;">
                        <h3 class="ca-title-fullname">{{fundEntity.fundFullname}}</h3>
                        <h4 class="ca-title-name">({{fundEntity.fundName}})</h4>
                        <div class="ca-m-t-5">
                            <span class="quit">拟投资</span>
                        </div>
                    </el-col>
                    <el-col :span="16">
                        <el-row class="ca-leng-28 ca-head-font">
                            <el-row>
                                <el-col :span="12">
                                    <span class="ca-font-color-gray ca-font-size-14">基金类型：</span>
                                    <span class="ca-font-size-14">{{fundEntity.fundType | getNameById('fundType')}}</span>
                                </el-col>
                                <el-col :span="12">
                                    <span class="ca-font-color-gray ca-font-size-14">拟设立规模（万元）：</span>
                                    <span class="ca-color__money ca-font-size-14">{{fundEntity.fundScale | format1}}</span>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <span class="ca-font-color-gray ca-font-size-14">存续期（年）：</span>
                                    <span class="ca-font-size-14">
                                        {{fundEntity.investmentPeriod}}
                                        <span v-if="fundEntity.investmentPeriod && fundEntity.exitPeriod">+</span>
                                        {{fundEntity.exitPeriod}}
                                    </span>
                                </el-col>
                                <el-col :span="12">
                                    <span class="ca-font-color-gray ca-font-size-14">基金经理：</span>
                                    <span class="ca-font-size-14">{{managerName}}</span>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">
                                    <span class="ca-font-color-gray ca-font-size-14">项目组成员：</span>
                                    <span class="ca-font-size-14 ca-m-l-10" v-for="(item, index) in managerTeam" :key="index">{{item}}</span>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12" v-if="FOF">
                                    <span class="ca-font-color-gray ca-font-size-14">母基金：</span>
                                    <span class="ca-font-size-14 ca-m-l-10" v-if='flag' v-for="(item, index) in motherList" :key="index">{{item}}</span>
                                </el-col>
                                <el-col :span="12">
                                    <span class="ca-font-color-gray ca-font-size-14">拟设立日期：</span>
                                    <span class="ca-font-size-14">{{fundEntity.establishTime == null ? "" :$moment(fundEntity.establishTime).format('YYYY-MM-DD')}}</span>
                                </el-col>
                            </el-row>
                            <el-row>
                                <span class="ca-font-color-gray ca-font-size-14">投资行业：</span>
                                <span class="ca-font-size-14 ca-m-l-10" v-for="i in industryList" :key="i.id">
                                        {{i.industry | getNameById('industry')}}
                                    </span>
                            </el-row>
                        </el-row>
                    </el-col>
                </el-row>
            </div>
        </div>
        <csHeader v-if="showEdit" @close="showEdit = false" :fundState="6" @update="update()"></csHeader>
    </div>
</template>
<script type="text/ecmascript-6">
    import {api} from '../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import { addRemind, isNoAuth } from '__service/utils';
    export default {
        data() {
            return {
                showEdit: false,
                isAuthEdit: isNoAuth('基金储备库-基金详情-编辑'),
                isAuthEditPre: isNoAuth('拟投资基金-基金详情-编辑'),
                flag: false,
                motherList: [],
                fundEntity: {
                    establishTime: '', //拟设立日期(或 成立时间 )
                    exitPeriod: '', //退出期
                    exitTime: '', //退出时间
                    fundCategory: '', //基金类别:对应字典表
                    fundFullname: '', //基金全称
                    fundName: '', //基金简称
                    fundScale: 0, //基金规模(或 拟设立规模)
                    fundState: 0, //设立状态：0：拟设立，1：已设立，2：退出中,3：已到期,4:母基金 对应字典表（d_type=fundState）
                    fundType: '', //基金类型:对应字典表（d_type=fundType）
                    id: '', //基金主id
                    investmentPeriod: '', //投资期
                    treeType: '1' //1：子基金；2：母基金 对应字典表：fundTree
                },
                fundUserList: [], //基金经理和基金团队
                fundMotherSonList: [ //投资母基金
                    {
                        fundMotherId: '', //母基金id
                        fundSonId: '', //子基金id
                        id: '' //主id
                    }
                ],
                managerName: '', //基金经理
                managerTeam: [], //基金成员
                industryList: [], //投资方向
            }
        },
        created() {
        },
        mounted() {
            this.getHeaderInfo()
            this.getFundMother()
        },
        props: {

        },
        watch: {
            'fundUserList': {
                handler: function () {
                    this.$emit('projectMan', this.managerName)
                },
                deep: true
            },
            'deleteStatus': {
                handler: function () {
                    this.$emit('deleteStatus', this.fundEntity.deleteStatus)
                },
                deep: true
            }
        },
        methods: {
            async update() {
                this.showEdit = false
                await this.getHeaderInfo()
                // 添加小红点
                await addRemind({
                    dataId: this.$route.params.itemId, // 业务id
                    dataTab: 0, // tab页顺序 head 也为0 新建为'-1'
                    dataType: 4, // 1拟投资项目,2已投资项目,3母基金,4拟设立基金,5已设立基金,6客户,7潜在项目
                });
                // 根据第三方组件来调用 父组件中定义的方法 重新获取小红点
                this.$root.Dot.$emit('getDotList');
                // 添加小红点 end
            },
            // 获取母基金
            getFundMother() {
                apiHttp(api.MOTHERFUD_LIST, {fundState: '4'}).then(ret => {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.fundMotherList = ret.data
                    }
                })
            },
            getHeaderInfo() {
                apiHttp(api.CHECK_HEADERINFO, {fundId: this.$route.params.itemId}).then(ret=> {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.fundEntity = ret.data.fundEntity
                        this.fundMotherSonList = ret.data.fundMotherSonList
                        this.fundUserList = ret.data.fundUserList
                        this.industryList = ret.data.industryList;//投资方向
                        this.$emit('deleteStatus', this.fundEntity.deleteStatus)
                        this.managerTeam = []
                        this.fundUserList.map(item => {
                            if (item.userType === '1') {
                                this.managerName = item.userName
                            } else {
                                this.managerTeam.push(item.userName)
                            }
                        })
                        this.motherList = []
                        // 获取母基金
                        if (this.fundMotherList) {
                            if (this.fundMotherSonList.length > 0 && this.fundMotherList.length > 0) {
                                this.flag = true
                                this.fundMotherList.map( fundItem => {
                                    this.fundMotherSonList.map( value => {
                                        if (fundItem.id === value.fundMotherId) {
                                            if (this.flag) {
                                                this.motherList.push(fundItem.fundName)
                                            }
                                        }
                                    })
                                })
                            }
                        }
                    }
                })
            },
        },
        components: {
            'csHeader': require('./edit'),//头部edit页
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .ca-title-fullname {
        font-size: 18px;
        line-height: 26px;
        color: #333;
    }
    .ca-title-name {
        font-size: 14px;
        line-height: 26px;
        color: #666;
        font-weight: normal;
    }
    .ca-align-right{
        font-size:20px;
    }
    .quit{
        width:51px;
        height:22px;
        background:#169bd5;
        display: inline-block;
        line-height:22px;
        color: #fff;
    }
    .ca-head-font .el-row{
        font-size:14px;
        color: #313131;
    }
    .ca-m-l-10 {
        margin-left: 10px;
    }
</style>